package example.字符串.回文对称;

public class Demo1 {
    public static int getLongestPalindrome(String A, int n) {
        int[][] dp = new int[n][n];
        char[] chars = A.toCharArray();
        int maxLen = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) {
                    continue;
                }
                //i--> 双指针
                //<--j
                int left = i, right = j;
                while (left <= right) {
                    if (left == right) {
                        dp[i][j] = 1 + dp[i][j];
                        break;
                    }
                    if (chars[left++] == chars[right--]) {
                        dp[i][j] = 2 + dp[i][j];
                    } else {
                        dp[i][j] = 1;
                        break;
                    }
                }
                maxLen = Math.max(dp[i][j], maxLen);
            }
        }
        return maxLen;
    }

    public static void main(String[] args) {
        System.out.println(getLongestPalindrome("baabccc", 7));
    }
}
